package com.itlaobing.spring.ioc.collection;

import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class CollectionInjectionTest1 {

    public @Test void injectSet(){

        String configLocation = "classpath*:com/**/collection.xml";
        AbstractApplicationContext context = new ClassPathXmlApplicationContext(configLocation);
        Person p = context.getBean("first" , Person.class);

        Set<String> adepts = p.getAdepts();
        System.out.println(adepts);
        System.out.println(adepts.getClass());

        context.close();
    }

    public @Test void injectList() {

        String configLocation = "classpath*:com/**/collection.xml" ;
        AbstractApplicationContext container = new ClassPathXmlApplicationContext( configLocation );

        Person p = container.getBean( "second" , Person.class );

        List<String> hobby = p.getHobby();
        System.out.println( hobby );
        System.out.println( hobby.getClass() );

        container.close();
    }

    public @Test void injectMap() {

        String configLocation = "classpath*:com/**/collection.xml" ;
        AbstractApplicationContext container = new ClassPathXmlApplicationContext( configLocation );

        Person p = container.getBean( "third" , Person.class );

        Map<String, LocalDate> luckyDays = p.getLuckyDays();
        System.out.println( luckyDays );
        System.out.println( luckyDays.getClass() );

        container.close();
    }

    public @Test void injectProperties() {

        String configLocation = "classpath*:com/**/collection.xml" ;
        AbstractApplicationContext container = new ClassPathXmlApplicationContext( configLocation );

        Person p = container.getBean( "fourth" , Person.class );

        Properties address = p.getAddress() ;
        System.out.println( address );

        container.close();
    }

}
